﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SaleManagement.Models;
using SaleManagement.Controllers;

namespace SaleManagement.modules
{
    public partial class usBranchList : BaseUC
    {
        BranchsController objController;
        public String Id_Branch;
        public int datarow;
        public bool add = false;
        public usBranchList()
            :base()
        {
            InitializeComponent();
            objController = new BranchsController();
        }
        public override void OnAdd(object send, EventArgs e)
        {
            add = true;
            frmAdd_Edit_Branch frmbran = new frmAdd_Edit_Branch();
            frmbran.Show();
        }
       
        protected override void OnLoad(EventArgs e)
        {
            DataGridView.DataSource = objController.select(2);       
        }

        public override void OnGridDataCellClick(object sender, DataGridViewCellEventArgs e)
        {
            Id_Branch = this.DataGridView.SelectedRows[0].Cells[0].Value.ToString();
            datarow = DataGridView.CurrentCell.RowIndex;
        }
         public override void InitGridData()
        {
            this.DataGridView.AutoGenerateColumns = false;
            this.DataGridView.ColumnHeadersVisible = true;
            DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
            columnHeaderStyle.BackColor = Color.Beige;
            columnHeaderStyle.Font = new Font("Verdana", 10, FontStyle.Bold);
            DataGridView.ColumnHeadersDefaultCellStyle = columnHeaderStyle;

            DataGridViewTextBoxColumn idColumn = new DataGridViewTextBoxColumn();
            idColumn.DataPropertyName = "id";
            idColumn.HeaderText = "ID";
            idColumn.Width = 50;

            DataGridViewTextBoxColumn created_atColumn = new DataGridViewTextBoxColumn();
            created_atColumn.DataPropertyName = "created_at";
            created_atColumn.HeaderText = "CreateAt";
            created_atColumn.Width=200;

            DataGridViewTextBoxColumn updated_atColumn = new DataGridViewTextBoxColumn();
            updated_atColumn.DataPropertyName = "updated_at";
            updated_atColumn.HeaderText = "UpdateAt";
            updated_atColumn.Width = 200;


            DataGridViewTextBoxColumn nameColumn = new DataGridViewTextBoxColumn();
            nameColumn.DataPropertyName = "name";
            nameColumn.HeaderText = "Name Branchs";
            nameColumn.Width = 308;

            DataGridViewTextBoxColumn warehourse_idColumn = new DataGridViewTextBoxColumn();
            warehourse_idColumn.DataPropertyName = "warehourse_id";
            warehourse_idColumn.HeaderText = "Warehourse id";
            warehourse_idColumn.Width = 100;

            DataGridViewTextBoxColumn addressColumn = new DataGridViewTextBoxColumn();
            addressColumn.DataPropertyName = "address";
            addressColumn.HeaderText = "Address";
            addressColumn.Width = 300;

            DataGridViewTextBoxColumn phoneColumn = new DataGridViewTextBoxColumn();
            phoneColumn.DataPropertyName = "phone";
            phoneColumn.HeaderText = "Phone";
            phoneColumn.Width = 150;
            DataGridView.Columns.Add(idColumn);
            DataGridView.Columns.Add(created_atColumn);
            DataGridView.Columns.Add(updated_atColumn);
            DataGridView.Columns.Add(warehourse_idColumn);
            DataGridView.Columns.Add(nameColumn);
            DataGridView.Columns.Add(addressColumn);
            DataGridView.Columns.Add(phoneColumn);
        }
       
    }
}
